#!/bin/sh
#echo "Content-Type: text/html"
echo "Content-Type: image/png"
echo "Content-Disposition: attachment; filename=image.png"

echo
SENTIDO=`echo "$QUERY_STRING"| tr "&" "\n"|
    grep "sentido="| cut -f 2 -d "=" |head -n1`
if [ "$SENTIDO" == "" ]; then
	echo
	touch sentido.txt

	SENTIDO=`cat sentido.txt`
	if [ "$SENTIDO" = "" ]; then
		SENTIDO="subir"
	fi
else
	echo "Todo OK"
fi
echo $SENTIDO>sentido.txt


echo
CONTEO=`echo "$QUERY_STRING"| tr "&" "\n"|
    grep "conteo="| cut -f 2 -d "=" |head -n1`

if [ "$CONTEO" = "" ]; then
	echo
	touch actual.txt
	VALOR=`cat actual.txt`
if [ "$VALOR" = "" ]; then
	VALOR="0"
fi
if [ "$SENTIDO" = "subir" ]; then
	VALOR=$(($VALOR + 1))
fi
if [ "$SENTIDO" = "bajar" ]; then
	if [ "$VALOR" -gt '0' ]; then
		VALOR=$(($VALOR -1))
	fi
fi
else
VALOR=$CONTEO
echo "Todo OK"
fi

echo $VALOR>actual.txt
echo "<hr>"
echo "valor $VALOR" 
echo "<hr>"
echo "sentido $SENTIDO" 
